/**
 *author:yhb
 */
package com.towker.frame.dao.rbac;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

import com.towker.core.db.*;
import com.towker.frame.model.rbac.RoleUser;

@Repository
public class RoleUserDao extends BaseDao<RoleUser, Long>
{
	@SuppressWarnings("unchecked")
	@Override
	public Class getEntityClass()
	{
		return RoleUser.class;
	}
	/**
	 * 根据用户删除角色用户分配*/
	public void delByUserid(long userid)
	{
		getSqlSessionTemplate().delete(getIbatisMapperNamespace() + ".delByUserid", userid);
	}
	/**
	 * 根据角色删除角色用户分配*/
	public void delByRoleid(long roleid)
	{
		getSqlSessionTemplate().delete(getIbatisMapperNamespace() + ".delByRoleid", roleid);
	}
	/**
	 * 根据系统删除角色用户分配*/
	public void delBySysid(Long sysid)
	{
		this.getSqlSessionTemplate().delete(getIbatisMapperNamespace() + ".delBySysid", sysid);
	}
	public void delUserRole(Long userid)
	{
		getSqlSessionTemplate().delete(getIbatisMapperNamespace()+".delUserRole", userid);
	}
	/**
	 * 根据系统与角色获得所有的已经分配的用户*/
	@SuppressWarnings("unchecked")
	public List<RoleUser> getRoleUsersBySystemAndRole(long systemid, long roleid)
	{
		Map<String, Long> map = new HashMap<String, Long>();
		map.put("systemid", systemid);
		map.put("roleid", roleid);
		return this.getSqlSessionTemplate().selectList(getIbatisMapperNamespace() + ".getRoleUsersBySystemAndRole", map);
	}
	/**
	 * 根据系统与角色获得所有的已经分配的用户*/
	@SuppressWarnings("unchecked")
	public List<RoleUser> getRoleUsersBySystemAndRoleAndAccount(long system, long role, String account)
	{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("system", system);
		map.put("role", role);
		map.put("account", account);
		return this.getSqlSessionTemplate().selectList(getIbatisMapperNamespace() + ".getRoleUsersBySystemAndRoleAndAccount", map);
	}
	/**
	 * 获得角色，根据系统与用户*/
	@SuppressWarnings("unchecked")
	public List<RoleUser> getRolesBySysAndUser(long sys, long user)
	{
		Map<String, Long> map = new HashMap<String, Long>();
		map.put("system", sys);
		map.put("user", user);
		return this.getSqlSessionTemplate().selectList(getIbatisMapperNamespace() + ".getRolesBySysAndUser", map);
	}
	/**
	 * 根据角色编号，获得所有角色用户分配*/
	@SuppressWarnings("unchecked")
	public List<RoleUser> getAssignedUserByRoleid(Long roleid)
	{
		return getSqlSessionTemplate().selectList(getIbatisMapperNamespace() + ".getAssignedUserByRoleid", roleid);
	}
}
